/**
 * 主要用于返回资产故障数据
 */
var experss = require('express');
var router = experss.Router();
var db = require("../public/javascripts/db");
var multer = require('multer');
var upload = multer();
var _ = require("lodash");

/* GET home page. */
router.get('/', function(req, res, next) {
    
    let equipmentid = _.trim(String(req.query.equipmentid));

    let data = {
        isSuccess: false,
        data: null,
        msg: '资产故障数据获取失败！'
    };
    let tempSql = 'select a.*, b.name assistantname, c.name assistant1name, d.name recorder '
    + 'From event_record a left join sys_user b on a.assistant=b.id '
    + 'left join sys_user c on a.assistant1=c.id left join sys_user d on a.recorderid=d.id';
    let sql = tempSql + " where equipmentid='" + equipmentid + "' and isfinished=0";
    console.log(sql);
    db.execute(sql, function(err, rows) {
        if(err) {
            return res.json(data);
        } else {
            if(rows.length > 0 ) {
                data.data = rows[0];
                data.isSuccess = true;
                data.msg = "资产故障数据获取成功！";
                return res.json(data);
            } else {
                return res.json(data);
            }
        }
    })
});

module.exports = router;